package com.wonders.hisdoctor.station.project.vaccine.controller;

import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.utils.validator.ValidateUtils;
import com.wonders.his.common.utils.validator.group.InsertGroup;
import com.wonders.hisdoctor.station.project.vaccine.service.VaccinationService;
import com.wonders.hisdoctor.station.project.vaccine.vo.GetDosageNumVO;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccinationCertVO;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccinationPrintVO;
import com.wonders.hisdoctor.station.project.vaccine.vo.VaccinationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 张澎_9970
 * @date 2021.6.24 下午 3:06 星期四
 * @desc: 接种登记_Controller
 */
@Api(tags = "接种登记")
@RestController
@RequestMapping("/vaccination")
public class VaccinationController {
    private VaccinationService vaccinationService;
    private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    @ApiOperation("保存")
    @PostMapping("save")
    public BaseResult<Integer> save(@RequestBody VaccinationVO vaccinationVO, HttpServletRequest request) {
        ValidateUtils.validateEntity(vaccinationVO.getPatVaccineRegister(), InsertGroup.class);
        return BaseResult.success(vaccinationService.save(vaccinationVO, request));
    }

    @ApiOperation("查询")
    @GetMapping("query")
    public BaseResult<VaccinationVO> query(String name, String idNo) {
        return BaseResult.success(vaccinationService.query(name, idNo));
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public BaseResult<Integer> delete(String vaccineInfoId, String vaccineDate) throws ParseException {
        final Date date = dateFormat.parse(vaccineDate);
        return BaseResult.success(vaccinationService.delete(vaccineInfoId, date));
    }

    @ApiOperation("打印")
    @PostMapping("print")
    public BaseResult<VaccinationCertVO> print(@RequestBody VaccinationPrintVO printVO) {
        return BaseResult.success(vaccinationService.print(printVO));
    }

    @ApiOperation("剂次数")
    @PostMapping("getDosageNum")
    public BaseResult<Integer> getDosageNum(@RequestBody GetDosageNumVO getDosageNumVO) {
        return BaseResult.success(vaccinationService.getDosageNum(getDosageNumVO));
    }

    @Autowired
    public void setVaccinationService(VaccinationService vaccinationService) {
        this.vaccinationService = vaccinationService;
    }
}
